home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / COSEmulator / COSEmulator- SRC / src / AnimiWindow.cpp < prev    next >
Encoding:
Text File  |  1998-06-21  |  5.1 KB  |  202 lines  |  [TEXT/CWIE]

  1. //===================================================================
  2. //=======================  Headers        =============================
  3.  
  4. #include "AnimiWindow.h"
  5. #include "GameUtilities.h"
  6. #include "Screen.h"
  7.  
  8. //===================================================================
  9. //=======================  Globals        =============================
  10.  
  11. OffScreenBuff    buff;
  12. rect            pic[ 20 ];
  13.  
  14. //===================================================================
  15. //=======================  #define        =============================
  16.  
  17.  
  18. //===================================================================
  19. //=======================  Function Prototypes    =====================
  20.  
  21. void    InitTHIng( void )
  22. {
  23.     MySetRectWH( &pic[ 0 ] , 0 , 0 , 124 , 124 );
  24.     MySetRectWH( &pic[ 1 ] , 124 , 0 , 124 , 124 );
  25.     MySetRectWH( &pic[ 2 ] , 248 , 0 , 124 , 124 );
  26.     MySetRectWH( &pic[ 3 ] , 372 , 0 , 124 , 124 );
  27.     MySetRectWH( &pic[ 4 ] , 496 , 0 , 124 , 124 );
  28.     MySetRectWH( &pic[ 5 ] , 620 , 0 , 124 , 124 );
  29.     
  30.     MySetRectWH( &pic[ 6 ] , 0 , 124 , 124 , 124 );
  31.     MySetRectWH( &pic[ 7 ] , 124 , 124 , 124 , 124 );
  32.     MySetRectWH( &pic[ 8 ] , 248 , 124 , 124 , 124 );
  33.     MySetRectWH( &pic[ 9 ] , 372 , 124 , 124 , 124 );
  34.     MySetRectWH( &pic[ 10 ] , 496 , 124 , 124 , 124 );
  35.     MySetRectWH( &pic[ 11 ] , 620 , 124 , 124 , 124 );
  36.     
  37.     MySetRectWH( &pic[ 12 ] , 0 , 248 , 124 , 124 );
  38.     MySetRectWH( &pic[ 13 ] , 124 , 248 , 124 , 124 );
  39.  
  40.     if( !buff.LoadPicBuff( 147 ) )
  41.         SysBeep(0);
  42. }
  43.  
  44. /*----------------------------------------------------------------------------\
  45.  
  46.     AnimiWindow :: Constructor
  47.  
  48. \----------------------------------------------------------------------------*/
  49.     AnimiWindow :: AnimiWindow( void )
  50. {
  51.     frame = 0;
  52. }
  53.  
  54. /*----------------------------------------------------------------------------\
  55.  
  56.     AnimiWindow :: Init
  57.  
  58. \----------------------------------------------------------------------------*/
  59. Boolean    AnimiWindow :: SetUp( short xLoc , short yLoc )
  60. {
  61.     width = 124;
  62.     height = 124;
  63.     
  64.     screenLoc.left = xLoc;
  65.     screenLoc.top = yLoc;
  66.     screenLoc.right = screenLoc.left + width;
  67.     screenLoc.bottom = screenLoc.top + height;
  68.     
  69.     window.NewBuff( width , height );
  70.     
  71.     DrawPicture( &buff , &pic[ frame ] , &window , &window.GetBoundsSize() );
  72.         
  73.     return true;
  74. }
  75.  
  76. /*----------------------------------------------------------------------------\
  77.  
  78.     AnimiWindow :: HandleMouseClick
  79.  
  80. \----------------------------------------------------------------------------*/
  81. void    AnimiWindow :: HandleMouseClick( Boolean down , point where )
  82. {
  83.     if( down )
  84.     {
  85.         draging = true;
  86.         start = where;
  87.     }
  88.     else
  89.     {
  90.         if( draging )
  91.         {
  92.             screen.AddRectToUpdate( screenLoc );
  93.             
  94.             MyOffSetRect( &screenLoc , where.x - start.x , where.y - start.y );
  95.  
  96.             screen.AddRectToUpdate( screenLoc );
  97.             
  98.             draging = false;
  99.         }
  100.     }
  101. }
  102.  
  103. /*----------------------------------------------------------------------------\
  104.  
  105.     AnimiWindow :: HandleMouseMove
  106.  
  107. \----------------------------------------------------------------------------*/
  108. void    AnimiWindow :: HandleMouseMove( point where )
  109. {
  110.     if( draging )
  111.     {
  112.         screen.AddRectToUpdate( screenLoc );
  113.         
  114.         MyOffSetRect( &screenLoc , where.x - start.x , where.y - start.y );
  115.         start = where;
  116.         
  117.         screen.AddRectToUpdate( screenLoc );
  118.     }
  119. }
  120.  
  121. /*----------------------------------------------------------------------------\
  122.  
  123.     AnimiWindow :: PointInWindow
  124.  
  125. - just saids if the point it inside the window area or not
  126. \----------------------------------------------------------------------------*/
  127. Boolean    AnimiWindow :: PointInWindow( point where )
  128. {
  129.     return SectPtRect( where , screenLoc );
  130. }
  131.  
  132. /*----------------------------------------------------------------------------\
  133.  
  134.     AnimiWindow :: Active
  135.  
  136. \----------------------------------------------------------------------------*/
  137. Boolean    AnimiWindow :: Front( void )
  138. {
  139.     return( front );
  140. }
  141.  
  142. /*----------------------------------------------------------------------------\
  143.  
  144.     AnimiWindow :: SetFront
  145.  
  146. \----------------------------------------------------------------------------*/
  147. void    AnimiWindow :: SetFront( Boolean f )
  148. {
  149.     front = f;
  150. }
  151.  
  152. /*----------------------------------------------------------------------------\
  153.  
  154.     AnimiWindow :: DrawToScreen
  155.  
  156. \----------------------------------------------------------------------------*/
  157. void    AnimiWindow :: DrawToScreen( rect *where , Boolean backGround )
  158. {
  159.     if( !backGround )
  160.     {
  161.         if( where == NULL )
  162.         {
  163.             screen.DrawGeneric( &window , &window.GetBoundsSize() , &screenLoc ,
  164.                         NULL , 0 , 0 , 0 );
  165.         }
  166.         else
  167.         {
  168.             screen.DrawGeneric( &window , &window.GetBoundsSize() , &screenLoc ,
  169.                         where , 0 , 0 , 0 );
  170.         }
  171.     }
  172.     else
  173.     {
  174.         if( where == NULL )
  175.         {
  176.             screen.DrawGeneric( &window , &window.GetBoundsSize() , &screenLoc ,
  177.                         NULL , kDrawTint , 16 , 0xffff );
  178.         }
  179.         else
  180.         {
  181.             screen.DrawGeneric( &window , &window.GetBoundsSize() , &screenLoc ,
  182.                         where , kDrawTint , 16 , 0xffff );
  183.         }
  184.     }
  185.  
  186. }
  187.  
  188. /*----------------------------------------------------------------------------\
  189.  
  190.     AnimiWindow :: Animate
  191.  
  192. \----------------------------------------------------------------------------*/
  193. void    AnimiWindow :: Animate( void )
  194. {    
  195.     DrawPicture( &buff , &pic[ frame ] , &window , &window.GetBoundsSize() );
  196.     screen.AddRectToUpdate( screenLoc );
  197.     
  198.     frame++;
  199.     
  200.     if( frame >= 13 )
  201.         frame = 0;
  202. }